package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.domain.AdvAreas;
import com.ruoyi.service.IAdvAreasService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * Controller
 *
 * @author ruoyi
 * @date 2024-05-27
 */
@RestController
@RequestMapping("/system/areas")
public class AdvAreasController extends BaseController
{
    @Autowired
    private IAdvAreasService advAreasService;

    /**
     * 查询列表
     */

    @PreAuthorize("@ss.hasPermi('system:areas:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdvAreas advAreas)
    {
//        startPage();
        List<AdvAreas> list = advAreasService.selectAdvAreasList(advAreas);
        return getDataTable(list);
    }

    /**
     * 导出列表
     */

    @PreAuthorize("@ss.hasPermi('system:areas:export')")
    @Log(title = "", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdvAreas advAreas)
    {
        List<AdvAreas> list = advAreasService.selectAdvAreasList(advAreas);
        ExcelUtil<AdvAreas> util = new ExcelUtil<AdvAreas>(AdvAreas.class);
        util.exportExcel(response, list, "数据");
    }

    /**
     * 获取详细信息
     */

    @PreAuthorize("@ss.hasPermi('system:areas:query')")
    @GetMapping(value = "/{busAreasId}")
    public AjaxResult getInfo(@PathVariable("busAreasId") Long busAreasId)
    {
        return success(advAreasService.selectAdvAreasByBusAreasId(busAreasId));
    }

    @GetMapping("getAreaList/{areaId}")
    public AjaxResult getAreaList(@PathVariable("areaId") Long areaId) {
        return  success(advAreasService.selectAdvAreasForOptions(areaId));
    }

    /**
     * 新增
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('system:areas:add')")
    @Log(title = "", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdvAreas advAreas)
    {
        return toAjax(advAreasService.insertAdvAreas(advAreas));
    }

    /**
     * 修改
     */

    @PreAuthorize("@ss.hasPermi('system:areas:edit')")
    @Log(title = "", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdvAreas advAreas)
    {
        return toAjax(advAreasService.updateAdvAreas(advAreas));
    }

    /**
     * 删除
     */

    @PreAuthorize("@ss.hasPermi('system:areas:remove')")
    @Log(title = "", businessType = BusinessType.DELETE)
	@DeleteMapping("/{busAreasIds}")
    public AjaxResult remove(@PathVariable Long[] busAreasIds)
    {
        return toAjax(advAreasService.deleteAdvAreasByBusAreasIds(busAreasIds));
    }
}
